package com.ag.work.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;

import com.ag.bean.TbPropose;
import com.ag.bean.TbProposeRecord;
import com.ag.bean.TbUser;
import com.ag.common.AjaxNotify;
import com.ag.common.BaseAction;
import com.ag.common.IPermissionService;
import com.ag.work.service.impl.ProposeRecordServiceImpl;
import com.ag.work.service.impl.ProposeServiceImpl;

@SuppressWarnings("serial")
public class ProposeAction extends BaseAction implements SessionAware{

	private static final Logger logger = Logger.getLogger(ProposeAction.class);
	/**
	 * 调用权限服务逻辑组件
	 */
	@Resource(name = "PermissionServiceImpl")
	private IPermissionService pms;
	private ProposeServiceImpl proposeServiceImpl;
	private ProposeRecordServiceImpl proposeRecordServiceImpl;
	private TbPropose propose = new TbPropose();
	private TbProposeRecord proposeRecord = new TbProposeRecord();
	private String PComments;
	private List<TbProposeRecord> tbProposeRecords;
	private String ajaxRst;
	/**
	 * 提供Map<String, Object>类型的Session变量，用来保存Struts2注入的Session上下文
	 */
	private Map<String, Object> sessionMap;
	
	@Override
	public void setSession(Map<String, Object> session) {
		this.sessionMap = session;
	}
	
	public void save(){
		proposeServiceImpl.save(propose);
		proposeRecord.setTbPropose(propose);
		proposeRecordServiceImpl.save(proposeRecord);

		this.outJsonString("呈批成功！");
	}

	public String find(){	
		TbUser user = pms.getCurrentUser(sessionMap);
		logger.info("UId:------"+user.getUId());
		String UId = user.getUId();
		try {
			this.tbProposeRecords = proposeRecordServiceImpl.findRecord(UId);
			ajaxRst = AjaxNotify.SUCCESS;
			return "new";
		} catch (Exception e) {
			e.printStackTrace();
			ajaxRst = AjaxNotify.NULLVALUE;
			return "new";
		}
	}
	
	public TbProposeRecord getProposeRecord() {
		return proposeRecord;
	}

	public void setProposeRecord(TbProposeRecord proposeRecord) {
		this.proposeRecord = proposeRecord;
	}

	public String getPComments() {
		return PComments;
	}

	public void setPComments(String pComments) {
		PComments = pComments;
	}

	public ProposeServiceImpl getProposeServiceImpl() {
		return proposeServiceImpl;
	}

	public void setProposeServiceImpl(ProposeServiceImpl proposeServiceImpl) {
		this.proposeServiceImpl = proposeServiceImpl;
	}

	public ProposeRecordServiceImpl getProposeRecordServiceImpl() {
		return proposeRecordServiceImpl;
	}

	public void setProposeRecordServiceImpl(
			ProposeRecordServiceImpl proposeRecordServiceImpl) {
		this.proposeRecordServiceImpl = proposeRecordServiceImpl;
	}

	public List<TbProposeRecord> getTbProposeRecords() {
		return tbProposeRecords;
	}

	public void setTbProposeRecords(List<TbProposeRecord> tbProposeRecords) {
		this.tbProposeRecords = tbProposeRecords;
	}

	public String getAjaxRst() {
		return ajaxRst;
	}

}
